package com.gxa.meiye.admin.controller.zy;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gxa.meiye.admin.service.UpdateService;
import com.gxa.meiye.core.common.JsonResult;
import com.gxa.meiye.core.pojo.domain.Consumer;
import com.gxa.meiye.core.pojo.domain.UserLocation;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: zy
 * @CreateTime: 2022-07-21  15:53
 */
@RestController
@Api(value="图片和别名",tags = "上传图片接口")
@RequestMapping("/user")
public class UpdateController {
    @Autowired
    private UpdateService updateService;
    //
    @PostMapping("/add")
    public Map add(String phone, String img,String nickName) throws JsonProcessingException {

        System.out.println(phone);
        System.out.println(img);
        System.out.println(nickName);
        Integer integer = updateService.selectAddUpdate(phone, img, nickName);
        JsonResult jsonResult=new JsonResult();
        if (integer!=0){
            jsonResult.setCode("1");
            jsonResult.setMsg("添加或修改成功");
        }
        jsonResult.setCode("0");
        jsonResult.setMsg("失败");

        return jsonResult.getMap();
    }
    @PostMapping("/select")
    public Map select(String phone){
        Consumer consumer = updateService.selectImg(phone);
        Map<String,String> map=new HashMap<>();
        map.put("img",consumer.getImg());
        map.put("name",consumer.getName());
        JsonResult jsonResult=new JsonResult();
        if (!StringUtils.isEmpty(consumer)){
            jsonResult.setCode("1");
            jsonResult.setData(map);
        }
        return jsonResult.getMap();
    }
}
